# -*- codeing = utf-8 -*-
# @Time : 2021/3/4 21:36
# @Atuthor: 朱朱
# @File: 183文件下载服务器.py
# @Software: PyCharm
import socket, os

# 1. 建立连接
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# 2. 绑定ip和端口号
server_socket.bind(('127.0.0.1',9090))

# 3. 建立监听
server_socket.listen(128)

# 4.接收请求,并解析ip和端口号
client_socket, client_addr = server_socket.accept()

# 5.解析数据
file_name = client_socket.recv(1024).decode('gbk')

if os.path.isfile(file_name):
    with open(file_name, 'rb') as file:
        content = file.read()
        client_socket.send(content)
else:
    print('文件不存在')